package cbbx_sm.utils;

import java.util.Random;

/**
 * Generate pseudo-random floating point values, with an approximately Gaussian
 * (normal) distribution.
 * 
 * Many physical measurements have an approximately Gaussian distribution; this
 * provides a way of simulating such values.
 */
public final class RandomGaussian {

	public static void main(String... aArgs) {
		RandomGaussian gaussian = new RandomGaussian(5);
		double MEAN = 200f;
		double VARIANCE = 100f;
		for (int idx = 1; idx <= 100; ++idx) {
			log("Generated : " + gaussian.getGaussian(MEAN, VARIANCE));
		}
	}
	private final Random fRandom;

	public RandomGaussian(int seed) {
		fRandom = new Random(seed);
	}

	public double getGaussian(double aMean, double aVariance) {
		return aMean + fRandom.nextGaussian() * aVariance;
	}

	public int getPositiveIntGaussian(double aMean, double aVariance) {
		double res = getGaussian(aMean, aVariance);
		if (res < 1) {
			res = 1;
		}
		return (int) Math.round(res);
	}
	private static void log(Object aMsg) {
		System.out.println(String.valueOf(aMsg));
	}
}
